package m.jclecai.com.adapter.holder;

import android.content.Context;
import android.support.annotation.LayoutRes;
import android.support.v4.content.ContextCompat;
import android.widget.TextView;

import butterknife.BindView;
import m.jclecai.com.R;
import m.jclecai.com.bean.RedPacketBean;

/**
 * Created by ZD on 2017/6/27.
 */

public class RedPkgHolder extends ViewHolder {
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_allMoney)
    TextView tvAllMoney;
    @BindView(R.id.tv_type)
    TextView tvType;

    public RedPkgHolder(Context context, @LayoutRes int resource) {
        super(context, resource);
    }

    public void init(RedPacketBean pkg, int flag) {
        tvTitle.setText("余额:" + String.valueOf(pkg.getRestmoney()) + "元");
        tvTime.setText(formatTime(pkg.getStarttime(), pkg.getEndtime()));
        tvAllMoney.setText("总额:" + String.valueOf(pkg.getAllmoney()));
        tvTime.setTextColor(ContextCompat.getColor(getContext(), R.color.white));
        tvTitle.setTextColor(ContextCompat.getColor(getContext(), R.color.white));
        tvType.setText(pkg.getTitle());
        if (flag > 0) {
            tvTime.setTextColor(ContextCompat.getColor(getContext(), R.color.color_f7ab91));
            tvTitle.setTextColor(ContextCompat.getColor(getContext(), R.color.color_f7ab91));
        }
    }

    String formatTime(String start, String end) {
        start = start.substring(start.indexOf("-") + 1, start.lastIndexOf(":"));
        end = end.substring(end.indexOf("-") + 1, end.lastIndexOf(":"));
        return start + "~" + end;
    }
}
